Axios.defaults.baseURL = project + '/onlineArchive/transfer/search';
let transferListUrl = project + '/onlineArchive/report/transferList';

let main ={
    el:"#app",
    data:function() {
        return {
            operationRecords:[],
            detailDialogVisible:false,
            loading_1:false,
            list:[],
            loading:false,
            search:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                orgIds:[],
                keyword:''
            },
            pageList:[],
            archivalStatus:[],
            archivalType:[],
            incomingWay:[],
            activeName:'first',
            orgs:[],
            props: {
                checkStrictly: true,
                lazy: true,
                value:'orgId',
                label:'orgName',
                lazyLoad (node, resolve) {
                    axios.get(constantUrl + '/divisionOwnedStores',{
                        params:{
                            id:node.data.orgId
                        }
                    }).then(function (response) {
                        resolve(response.data.data);
                    })
                }
            },
            detailForm:{},
            loanCoreStatus:[],
            loading_dialog:false,
            searchArea:{
                searchTable:{
                    height:40,
                    isSimple:true
                }
            }
        }
    },
    computed: {
        // 计算属性的 getter
        tableHeight: function () {
            let height = window.parent.document.getElementById('content-main').clientHeight;
            return height - this.searchArea.searchTable.height- 125;
        }
    },
    beforeMount:function(){
        this.init();
    },
    methods:{

        /**
         * 重置查询条件
         * @param table
         */
        resetSearch: function (table) {
            if (table == 'searchTable') {
                this.search = {
                    pagination:{
                        pageNum: 1,
                        pageSize: 10,
                        total:0,
                    },
                    applicationDate:[],
                    loanTime:[],
                    applicationNo:'',
                    customerName:'',
                    productName:'',
                    incomingWay:'',
                    insuredName:'',
                    archivalType:'',
                    archivalStatus:'',
                    orgIds:[],
                    keyword:''
                };
                this.initPageList();
                return;
            } else {
                return;
            }
        },

        /**
         * 展开  收缩查询区域
         * @param table
         */
        showclick:function(table){
            this.searchArea[table].isSimple = !this.searchArea[table].isSimple;
            let that =this;
            setTimeout(function () {
                that.searchArea[table].height = window.document.getElementById(table).clientHeight ;
            },500)
        },

        init:function(){
            let that = this;
            axios.all([getArchivalStatusList(),getArchivalTypeList(),getIncomingWayList(),getDivisions(),getloanCoreStatusList()])
                .then(axios.spread(function (archivalStatus,archivalType,incomingWay,divisoins,loanCoreStatus) {
                    that.archivalStatus = archivalStatus.data.data;
                    that.archivalType = archivalType.data.data;
                    that.incomingWay = incomingWay.data.data;
                    that.orgs = divisoins.data.data;
                    that.loanCoreStatus = loanCoreStatus.data.data;
                })).then(function () {
                that.initPageList();
            });
        },
        /**
         *获取数据
         */
        getPageList:function(){
            let that = this;
            that.loading_1 = true;
            Axios({
                method: 'post',
                url: '/pageList',
                data: that.search
            })
                .then(function (response) {
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        that.loading_1 = false;
                        return;
                    }
                    that.pageList = response.data.list;
                    that.search.pagination.total = response.data.total;
                    that.loading_1 = false;
                })
                .catch(function (error) {
                    that.noticeFailure(that);
                    that.loading_1 = false;
                });
        },
        /**
         * 初始化数据列表，（加载第一页数据）
         */
        initPageList:function(){
            this.tablePageNumChange(1);
        },
        /**
         * 列表页码改变时触发
         * @param pageNum
         */
        tablePageNumChange:function(pageNum){
            this.search.pagination.pageNum = pageNum;
            this.getPageList();
        },
        /**
         * 数据列表，每页条数改变时触发
         * @param pageSize
         */
        tablePageSizeChange:function(pageSize){
            this.search.pagination.pageNum = 1;
            this.search.pagination.pageSize = pageSize;
            this.getPageList();
        },
        /**
         * 日期列格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        dateTimeFormatter:function(row, column, cellValue, index){
            return dateFormatter(cellValue);
        },
        /**
         * 是否格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        booleanFormatter:function(row,column,cellValue,index){
            return booleanFormatter(cellValue);
        },
        /**
         * 档案状态格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        archivalStatusFormatter:function(row,column,cellValue,index){
            for(let i = 0 ; i < this.archivalStatus.length ; i++){
                if (this.archivalStatus[i].code == cellValue){
                    return this.archivalStatus[i].description;
                }
            }
            return "";
        },
        /**
         * 档案类型格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        archivalTypeFormatter:function(row,column,cellValue,index){
            for(let i = 0 ; i < this.archivalType.length ; i++){
                if (this.archivalType[i].code == cellValue){
                    return this.archivalType[i].value;
                }
            }
            return "";
        },
        /**
         * 进件方式格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        incomingWayFormatter:function(row, column, cellValue, index){
            for(let i = 0 ; i < this.incomingWay.length ; i++){
                if (this.incomingWay[i].code == cellValue){
                    return this.incomingWay[i].value;
                }
            }
            return "";
        },


        /**
         * 获取分部数据
         */
        getData:function(){
            let that = this;
            that.loading = true;
            Axios.get('/list',{
                baseURL:transferListUrl,
                timeout: 120000,
            })
                .then(function (response) {
                    console.log(response);
                    that.loading = false;
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.list = response.data;
                })
                .catch(function (error) {
                    noticeFailure(that);
                    that.loading = false;
                });
        },
        /**
         * 获取分部下门店数据
         * @param tree
         * @param treeNode
         * @param resolve
         */
        load:function(tree, treeNode, resolve) {
            let that = this;
            Axios.get('/load',{
                baseURL:transferListUrl,
                params:{divisionCode:tree.divisionCode}
            })
                .then(function (response) {
                    console.log(response);
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    resolve(response.data)
                })
                .catch(function (error) {
                    noticeFailure(that);
                });
        },
        /**
         * 下载门店移交清单
         * @param row
         */
        downloadStoreTransferList:function(){
            window.location.href = transferListUrl + '/download/store';
        },
        /**
         * 下载分部移交清单
         * @param row
         */
        downloadDivisionTransferList:function(){
            window.location.href = transferListUrl + '/download/division';
        },
        /**
         * 查看详情 &  操作记录
         * @param scope
         */
        detail:function(scope){
            this.loading_dialog = true;
            this.detailDialogVisible = true;
            let that =this;
            axios.all([that.getOperationRecords(scope.row.id),that.getDetail(scope.row.originalIncomingId)])
                .then(axios.spread(function (operationRecords,detail) {
                    that.operationRecords = operationRecords.data.data;
                    that.detailForm = detail.data.data;
                    that.detailFormatter();
                })).then(function () {
                    that.loading_dialog = false;
            });
        },
        /**
         * detailForm数据格式化
         */
        detailFormatter(){
            this.detailForm.applicationDate = dateTimeFormatter(this.detailForm.applicationDate);
            this.detailForm.loanTime = dateTimeFormatter(this.detailForm.loanTime);
            for(let i = 0 ; i < this.incomingWay.length ; i++){
                if (this.incomingWay[i].code == this.detailForm.incomingWay){
                    this.detailForm.incomingWay =  this.incomingWay[i].value;
                    break;
                }
            }
            for(let i = 0 ; i < this.archivalType.length ; i++){
                if (this.archivalType[i].code == this.detailForm.archivalType){
                    this.detailForm.archivalType = this.archivalType[i].value;
                    break;
                }
            }
            for(let i = 0 ; i < this.loanCoreStatus.length ; i++){
                if (this.loanCoreStatus[i].code == this.detailForm.loanCoreStatus){
                    this.detailForm.loanCoreStatus = this.loanCoreStatus[i].value;
                    break;
                }
            }
            this.detailForm.loanCoreSystemLastTime = dateTimeFormatter(this.detailForm.loanCoreSystemLastTime);
            this.detailForm.claimType = '--';
            this.detailForm.claimStatus = '--';
            this.detailForm.claimDate = dateTimeFormatter(this.detailForm.claimDate);
            this.detailForm.cancelTime = dateTimeFormatter(this.detailForm.cancelTime);
        },
        /**
         * 获取操作记录
         * @param id
         */
        getOperationRecords:function(id){
            return axios.get(project + '/onlineArchive/transfer/search/operationRecords',{params:{id:id}})
        },
        /**
         * 获取详情记录
         * @param id
         */
        getDetail:function(id){
            return axios.get(project + '/onlineArchive/transfer/search/detail',{params:{id:id}})
        },
        /**
         * 点击tab页切换时执行
         * @param tab
         */
        tabClick:function(tab){
            if (tab.name == 'first') {
                this.initPageList();
                return;
            }
            if (tab.name == 'second') {
                this.getData();
                return;
            }
        }
    }
};
new Vue(main);